package org.example;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class MemoryController {

//    private static final int OBJECTS_TO_ALLOCATE = 10_000_000;

    private static final int OBJECTS_TO_ALLOCATE = 10_000;

    @GetMapping("/allocate")
    public String allocateMemory() {
        List<Object> list = new ArrayList<>();
        for (int i = 0; i < OBJECTS_TO_ALLOCATE; i++) {
            list.add(new Object());
        }
//        System.gc(); // 请求垃圾收集
        return "Allocated " + OBJECTS_TO_ALLOCATE + " objects!";
    }
}
